package com.beetlestech.nfe.main.biz.com.impl;

import java.util.ArrayList;
import java.util.List;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.fw.core.util.StringUtil;
import com.beetlestech.nfe.main.biz.com.HbVOrderList;
import com.beetlestech.nfe.main.biz.com.dto.VorderinfolistInfoDTO;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.base.StatementDTO;
import com.beetlestech.nfe.main.db.base.StatementUtil;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.view.VorderinfolistDTO;

public class HbVOrderListImpl extends AbstractDBLogic implements HbVOrderList, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {
	
	public VorderinfolistInfoDTO[]  getOrderList(
			Integer orderNo,
			String studentName,
			Integer orderStateCid,
			Integer paymenttype){
		List<VorderinfolistInfoDTO> orderList = new ArrayList<VorderinfolistInfoDTO>();
		List<VorderinfolistDTO> orderListDB = new ArrayList<VorderinfolistDTO>();
		VorderinfolistDTO vorderinfolistDTO =new VorderinfolistDTO();
		StatementDTO statementDTO = new StatementDTO();
		if(orderNo!=null && orderNo!=-1){
			StatementUtil.andWhere(statementDTO, VorderinfolistDTO.COLUMN_ORDER_ID, StatementUtil.KEYWORD.LIKE ,orderNo);
		}
		if(!StringUtil.isEmpty(studentName)){
			StatementUtil.andWhere(statementDTO, VorderinfolistDTO.COLUMN_STUDENTNAME, StatementUtil.KEYWORD.LIKE ,studentName);
		}
		if(orderStateCid!=0){
			StatementUtil.andWhere(statementDTO, VorderinfolistDTO.COLUMN_ORDER_STATECID, StatementUtil.KEYWORD.EQUAL ,orderStateCid);
			StatementUtil.andWhere(statementDTO, VorderinfolistDTO.COLUMN_ORDER_STATEPID, StatementUtil.KEYWORD.EQUAL ,4);
		}
		if(paymenttype!=null){
			StatementUtil.andWhere(statementDTO, VorderinfolistDTO.COLUMN_PAYMENTTYPECID, StatementUtil.KEYWORD.EQUAL ,paymenttype);
			StatementUtil.andWhere(statementDTO, VorderinfolistDTO.COLUMN_PAYMENTTYPEPID, StatementUtil.KEYWORD.EQUAL ,9);
			
		}
		vorderinfolistDTO.set_dynamicWhereCondition(statementDTO.getSQLStatement());
		orderListDB=queryDAO.queryForObjectList(VorderinfolistDTO.SQL_SEARCH, vorderinfolistDTO);
		if(orderListDB==null || orderListDB.size()==0){
			createApplicationException("errMsg", "没找到要查询的信息");
		}else{
			for(VorderinfolistDTO item:orderListDB){
				orderList.add(convertToVorderListInfo(item));
			}
		}
		return orderList.toArray(new VorderinfolistInfoDTO[orderList.size()]);
		
	}
	
	private VorderinfolistInfoDTO convertToVorderListInfo(VorderinfolistDTO item){
		VorderinfolistInfoDTO vorderinfolistInfoDTO = new VorderinfolistInfoDTO();
		vorderinfolistInfoDTO.setusername(item.getusername());
		vorderinfolistInfoDTO.setstudentname(item.getstudentname());
		vorderinfolistInfoDTO.setorderdate(item.getorderdate());
		vorderinfolistInfoDTO.setorderid(item.getorderid());
		vorderinfolistInfoDTO.setorderstate(item.getorderstate());
		vorderinfolistInfoDTO.setpaymentdate(item.getpaymentdate());
		vorderinfolistInfoDTO.setpaymenttype(item.getpaymenttype());;
		vorderinfolistInfoDTO.setprice(item.getprice());
		vorderinfolistInfoDTO.setorderstatecid(item.getorderstatecid());
		vorderinfolistInfoDTO.setPhone(item.getphone());
		return vorderinfolistInfoDTO;
	}

}
